home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / comm / news / slrn-src.lha / slrn / doc / README.macros < prev    next >
Text File  |  1999-04-27  |  8KB  |  258 lines

  1. -*- mode: text; mode: fold; -*-
  2. The purpose of this note is to provide some instructions on extending
  3. the newsreader in its macro language.  It consists of two parts: an
  4. overview of macros and the reference manual for slrn intrinsic
  5. functions.
  6.  
  7. {{{ Introduction 
  8.  
  9. The present implementation does not provide many hooks into the
  10. newsreader.  More capabilities will be added in subsequent releases.
  11.       
  12. When slrn is started, it reads the .slrnrc user initialization file.
  13. That file may contain one or more `interpret' commands causing the
  14. newsreader to load the specified S-Lang scripts, e.g.,
  15.  
  16.     interpret ".slrn.sl"
  17.     interpret "src/slrn/macros/search.sl"
  18.  
  19. Each script must obey the syntax of the S-Lang language.  See the
  20. slang documentation from www.s-alng.org more more information about
  21. the syntax.
  22.  
  23. Several pre-written macros are included in the slrn distribution in
  24. the macro subdirectory.
  25.  
  26.  
  27. ---------------------------------------------------------------------------
  28. Defining Key Macros
  29. ---------------------------------------------------------------------------
  30.  
  31.     Although one is able to bind keys to specific functions via lines
  32.     of the form
  33.     
  34.          setkey group "refresh_groups"  "G"
  35.      
  36.     in the .slrnrc file, it is not possible to defined more
  37.     complicated actions in this manner.  However, macros can be
  38.     defined by using a S-Lang script.  For example, the
  39.     `refresh_groups' internal function refreshes the newsgroups but it
  40.     does not cause the cursor to move to the top of the newsgroup
  41.     list.  On the other hand, the internal function `bob' moves to the
  42.     top of the list but it does not refresh the groups.  One can
  43.     define a S-Lang function to perform both actions:
  44.     
  45.          define refresh_groups_bob ()
  46.      {
  47.          call ("refresh_groups");
  48.          call ("bob");
  49.      }
  50.      
  51.     and bind it to a key:
  52.     
  53.          definekey ("refresh_groups_bob", "g", "group");
  54.      
  55.     Note: It is not yet possible to write this as:
  56.     
  57.         define refresh_groups_bob ()
  58.     {
  59.         refresh_groups ();
  60.         bob ();
  61.     }
  62.  
  63.     This restriction will be lifted in the future.
  64.     
  65.     The `definekey' function takes 3 arguments:
  66.     
  67.          function to execute
  68.      keybinding
  69.      keymap name   ("article" or "group")
  70.      
  71.     Here is another macro that may be used in article mode.  It
  72.     performs a regular expression search for subjects.
  73.     
  74.     variable Last_Search_Str = "";
  75.     define re_subject_search_forward ()
  76.     {
  77.        variable str;
  78.        
  79.        ERROR_BLOCK
  80.          {
  81.            () = header_up (1);
  82.          }
  83.     
  84.        !if (header_down (1)) return;
  85.     
  86.        str = read_mini ("Subject re-search fwd", Last_Search_Str, "");
  87.     
  88.        !if (strlen (str))
  89.          return;
  90.     
  91.        Last_Search_Str = str;
  92.        !if (re_fsearch_subject (str))
  93.          error ("Not found.");
  94.     }
  95.     
  96.     To bind it to, e.g., `s' in the article keymap, use:
  97.    
  98.     definekey ("re_subject_search_forward", "s", "article");
  99.     
  100.  
  101.     Some slrn keyboard functions require a ``prefix argument''.
  102.     Many people find the use of prefix arguments somewhat strange.
  103.     For example, instead of typing `ESC 1 ESC p' to reconstruct a thread,
  104.     one can simply use the function:
  105.     
  106.         define my_recreate_thread ()
  107.     {
  108.         set_prefix_argument (1);
  109.         call ("get_parent_header");
  110.     }
  111.     
  112.    Here is a function that pipes the current article to a
  113.    command called `most' (a paging program similar to more/less):
  114.    
  115.         define pipe_to_most ()
  116.     {
  117.         pipe_article ("most");
  118.     }
  119.     definekey ("pipe_to_most", "&", "article");
  120.  
  121.    Here it has been bound to the `&' key.  Most likely one will want
  122.    to pipe the article to a shell script for further processing.
  123.    
  124.    Some of the built-in keyboard functions will prompt for a
  125.    string.  For example, in article mode, pressing the `:' key will
  126.    prompt for an filename.  The function `set_input_string' may be
  127.    used to provide a response to such a prompt, e.g.,
  128.    
  129.       % The `:' command will prompt for a filename.
  130.       set_input_string ("/tmp/decoded");
  131.       call ("decode");
  132.  
  133.    For functions that prompt for a single character, such as 
  134.    
  135.       Do you really want to quit? [Y]es No
  136.       
  137.    a similar intrinsic function, set_input_chars, may be used to
  138.    provide the answer.
  139.    
  140.    
  141. ---------------------------------------------------------------------------
  142. Hooks
  143. ---------------------------------------------------------------------------
  144.    
  145. Currently, the newsreader
  146. recognizes the following hooks:
  147.  
  148.    startup_hook
  149.       This hook is called right after the newsreader is initialized
  150.       and immediately before checking for news.  This hook allows
  151.       the user to set variables on a server by server basis.
  152.       
  153.       Here is an example:
  154.       
  155.          define startup_hook ()
  156.      {
  157.        !if (strcmp (server_name (), "uhog"))
  158.          {
  159.            set_integer_variable ("lines_per_update", 20);
  160.            set_integer_variable ("read_active", 0);
  161.          }
  162.      }
  163.  
  164.       It simply sets the `lines_per_update' variable to 20 and turns
  165.       off reading of the active file if the servername is `uhog' (it
  166.       is a slow server).
  167.  
  168.    group_mode_startup_hook
  169.       This hook is called after checking for news and immediately
  170.       before entering the main keyboard loop.  When called, group mode
  171.       will be active
  172.       
  173.    group_mode_hook
  174.       This hook will be called whenever group mode is entered.  This
  175.       includes the times when one exists article mode back to group
  176.       mode.
  177.  
  178.    pre_article_mode_hook
  179.       This hook is similar to `article_mode_hook' except that it is
  180.       called before any headers for the group have been retrieved.
  181.  
  182.    article_mode_hook
  183.       This hook is called during article mode after headers have been
  184.       retrieved but before sorting them.  One can use this hook to set
  185.       variables based on the group name.  For example,
  186.  
  187.       define article_mode_hook ()
  188.       {
  189.          variable sorting_method = 7;
  190.      variable author_display = 2;
  191.          variable signature_file = ".signature";
  192.      
  193.          if (is_substr (current_newsgroup (), "binaries")
  194.          or is_substr (current_newsgroup (), "pictures"))
  195.        {
  196.           sorting_method = 3;
  197.           author_display = 0;
  198.        }
  199.  
  200.      if (0 == strncmp (current_newsgroup (), "comp.", 5))
  201.        signature_file = ".nerd-signature";
  202.        
  203.      set_integer_variable ("sorting_method", sorting_method);
  204.      set_integer_variable ("author_display", author_display);
  205.      set_string_variable ("signature", signature_file);
  206.       }
  207.       
  208.      changes the `sorting_method' and `author_display' variables to
  209.      something more appropriate for newgroups which contain encoded
  210.      articles.
  211.      
  212.    header_number_hook
  213.      If defined, this function will be called after selecting a header
  214.      via a header number.
  215.   
  216.    reply_hook
  217.      Function called when replying to poster.
  218.   
  219.    followup_hook
  220.      Function called when following up to an article.
  221.      
  222.    post_hook
  223.      Function called when posting an article.
  224.      
  225.    forward_hook
  226.      Function called when forwarding an article to someone.
  227.      
  228.    resize_screen_hook
  229.      This hook will be called whenever the screen size changes.
  230.      
  231.    post_filter_hook
  232.      This hook may be called just before slrn attempts to post a file.
  233.      The hook is only called if the user selects the filter option
  234.      from the prompt:
  235.      
  236.          Post the message? Yes, No, Edit, poStpone, Filter
  237.  
  238.      This hook takes a single parameter: the name of the file that
  239.      slrn is about to post.  Thus it must be declared as:
  240.        
  241.        define post_filter_hook (file);
  242.        
  243.      See macros/ispell.sl for an example.
  244.       
  245. }}}
  246.  
  247. ---------------------------------------------------------------------------
  248. Command Reference
  249. ---------------------------------------------------------------------------
  250. The above examples used ``intrinsic'' functions such as `call',
  251. `set_integer_variable', etc.  This section describes all slrn
  252. intrinsic functions that are available via the interpreter.  The code
  253. S-Lang langauge includes many others such as `strcmp' and `is_substr'
  254. which are not described here.
  255.  
  256. See slrnfuns.txt for detailed information about the slrn intrinsic
  257. functions. 
  258.